#include "Engine.h"

#include <map>

#include "EngineStateSleeping.h"
#include "EngineStateWatching.h"
#include "Piece.h"

using namespace Rorn::Chess::TheCorruptRook;

Engine::Engine(Rorn::Chess::IAppSender* appSender) 
	: appSender_(appSender), currentPosition_(), currentPlayer_(Player::White), currentState_(NULL)
{
	ChangeState(new EngineStateSleeping());
}

/*virtual*/ Engine::~Engine(void)
{
	if(currentState_ != NULL)
		delete currentState_;
}

void Engine::ChangeState(EngineState* newState)
{
	if(currentState_ != NULL)
		delete currentState_;

	currentState_ = newState;
}

/*virtual*/ void Engine::StartNewGame()
{
	currentPosition_.Reset();
	currentPlayer_ = Player::White;

	ChangeState(new EngineStateWatching(*this));
}

/*virtual*/ void Engine::Update()
{
	currentState_->Update();
}
